package com.jinlejia.feedback.idea.ui.adapter;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.freedom.yefeng.yfrecyclerview.YfListAdapter;
import com.freedom.yefeng.yfrecyclerview.YfSimpleViewHolder;
import com.jinlejia.feedback.R;
import com.jinlejia.feedback.idea.ui.bean.FbSearchQuestionHistoryBean;

import java.util.ArrayList;

/**
 * @author SongJiaTai
 * @description:问题搜索历史Adapter
 * @date :2019/7/2 10:43
 */
public class FbSearchHistoryAdapter extends YfListAdapter{

    public FbSearchHistoryAdapter(ArrayList data) {
        super(data);
    }

    @Override
    public RecyclerView.ViewHolder onCreateDataViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fb_item_search, parent, false);
        return new HistoryViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateEmptyViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fb_empty_layout, parent, false);
        TextView txt = (TextView) view.findViewById(R.id.id_tips);
        txt.setText("暂无历史");
        return new YfSimpleViewHolder(view);
    }

    @Override
    public void onBindDataViewHolder(RecyclerView.ViewHolder holder, int position) {
        Object o = mData.get(position);
        if (o instanceof FbSearchQuestionHistoryBean){
            ((HistoryViewHolder) holder).tvSearName.setText(((FbSearchQuestionHistoryBean) o).getName());
            ((HistoryViewHolder) holder).itemView.setTag(mData.get(position));
        }
    }


    @Override
    public void onBindFooterViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindFooterViewHolder(holder, position);
    }


    @Override
    public RecyclerView.ViewHolder onCreateFooterViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fb_footer_clear, parent, false);
        return new YfSimpleViewHolder(view);
    }

    static final class HistoryViewHolder extends RecyclerView.ViewHolder {
        TextView tvSearName;

        public HistoryViewHolder(View itemView) {
            super(itemView);
            tvSearName = itemView.findViewById(R.id.tv_search_name);

        }
    }
}
